package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.SysHz;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsOwnerShipmentorderconfig;
import com.jy.wms.service.WmsOwnerShipmentorderconfigService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.List;
import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsOwnerShipmentorderconfigController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Jane
 * @Date Fri Dec 29 17:07:20 CST 2017
 */
@Controller
@RequestMapping("/wmsownershipmentorderconfig")
@Api(value = "/wmsownershipmentorderconfig", description = "发运订单导入配置信息")
public class  WmsOwnerShipmentorderconfigController extends BaseController<WmsOwnerShipmentorderconfigService,WmsOwnerShipmentorderconfig> {

    @PostMapping(value = "list")
    @ApiOperation(value = "查询信息",response = JSONObject.class, notes = "查询信息")
    public @ResponseBody ResultPage<WmsOwnerShipmentorderconfig> getWmsOwnerShipmentorderconfig(@RequestBody WmsOwnerShipmentorderconfig entity,HttpSession session) {
        Page<WmsOwnerShipmentorderconfig> list= baseService.baseSelectPage(entity);
            return renderPage(list);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除信息",response = JSONObject.class, notes = "删除信息")
    public @ResponseBody JsonResult deleteWmsOwnerShipmentorderconfig(@RequestBody List<String> ids) {
        Integer flag=baseService.baseDeleteBathPrimaryKeys(ids);
        return renderSuccess("删除成功");
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增发运订单导入配置信息",response = JSONObject.class, notes = "新增发运订单导入配置信息")
    public @ResponseBody JSONObject addWmsOwnerShipmentorderconfig(@RequestBody WmsOwnerShipmentorderconfig entity,HttpSession session) {
        try{
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            String ckid=userinfo.getUser().getOrgId().get(0).toString();//获取仓库ID
            List<SysHz> hz=(List<SysHz>)session.getAttribute(BaseSessionInfo.SessionConsignor);
            String sshzid=hz.get(0).getHzid();//获取货主Id
            entity.setId(UUIDUtils.uuid());
            entity.setCkid(ckid);
            entity.setSshzid(sshzid);
            baseService.baseInsert(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"新增发运订单导入配置信息成功","",  JSONObject.fromObject(entity).toString());
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "新增发运订单导入配置信息失败", e.getMessage(), "");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "新增发运订单导入配置信息失败", e.getMessage(), "");
        }
    }

    @GetMapping(value = "getWmsOwnerShipmentorderconfig/{ssddqdid}")
    @ApiOperation(value = "查看单个发运订单导入配置信息",response = JSONObject.class, notes = "GET查看单个发运订单导入配置信息")
    public @ResponseBody JSONObject getWmsOwnerShipmentorderconfigById(@PathVariable("ssddqdid") String ssddqdid) {
        WmsOwnerShipmentorderconfig entity=baseService.baseSelectByPrimaryKey(ssddqdid);
        return JSONObject.fromObject(entity);
    }
    @PostMapping(value = "edit")
    @ApiOperation(value = "编辑发运订单导入配置信息",response = JSONObject.class, notes = "编辑发运订单导入配置信息")
    public @ResponseBody JSONObject editWmsOwnerShipmentorderconfig(@RequestBody WmsOwnerShipmentorderconfig entity) {
        try{
            baseService.baseUpdateByPrimaryKeySelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"编辑发运订单导入配置信息成功","",  JSONObject.fromObject(entity).toString());
        }catch (ServiceException e){
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "编辑发运订单导入配置信息失败", e.getMessage(), "");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "编辑发运订单导入配置信息失败", e.getMessage(), "");
        }
    }
}
